﻿using System;
using Glue;
using Xunit;

namespace GluePerformanceTesting
{
    public class Autorelating
    {
        private readonly PerformanceMeasure measurer;

        private class DomainOne { public String Prop1 { get; set; }}
        private class GuiOne { public String Prop1 { get; set; } }

        private class DomainTen
        {
            public String Prop1 { get; set; }
            public String Prop2 { get; set; }
            public String Prop3 { get; set; }
            public String Prop4 { get; set; }
            public String Prop5 { get; set; }
            public String Prop6 { get; set; }
            public String Prop7 { get; set; }
            public String Prop8 { get; set; }
            public String Prop9 { get; set; }
            public String Prop10 { get; set; }
        }
        private class GuiTen
        {
            public String Prop1 { get; set; }
            public String Prop2 { get; set; }
            public String Prop3 { get; set; }
            public String Prop4 { get; set; }
            public String Prop5 { get; set; }
            public String Prop6 { get; set; }
            public String Prop7 { get; set; }
            public String Prop8 { get; set; }
            public String Prop9 { get; set; }
            public String Prop10 { get; set; }
        }
        
        public Autorelating()
        {
            measurer = PerformanceMeasure.GetInstance();
        }

        [Fact]
        public void Autorelating_one_property()
        {
            measurer.Run("Autorelating one member", ()=>
            {
                var mapping = new Mapping<DomainOne, GuiOne>();
                mapping.AutoRelateEqualNames();
            });
        }

        [Fact]
        public void Manually_relating_one_property()
        {
            measurer.Run("Manually relating one member", () =>
            {
                var mapping = new Mapping<DomainOne, GuiOne>();
                mapping.Relate(x=>x.Prop1,y=>y.Prop1);
            });
        }

        [Fact]
        public void Autorelating_ten_properties()
        {
            measurer.Run("Autorelating ten properties", () =>
            {
                var mapping = new Mapping<DomainTen, GuiTen>();
                mapping.AutoRelateEqualNames();
            });
        }

        [Fact]
        public void Manually_relating_ten_properties()
        {
            measurer.RunLong("Manually relating ten properties", () =>
            {
                var mapping = new Mapping<DomainTen, GuiTen>();
                mapping.Relate(x => x.Prop1, y => y.Prop1);
                mapping.Relate(x => x.Prop2, y => y.Prop2);
                mapping.Relate(x => x.Prop3, y => y.Prop3);
                mapping.Relate(x => x.Prop4, y => y.Prop4);
                mapping.Relate(x => x.Prop5, y => y.Prop5);
                mapping.Relate(x => x.Prop6, y => y.Prop6);
                mapping.Relate(x => x.Prop7, y => y.Prop7);
                mapping.Relate(x => x.Prop8, y => y.Prop8);
                mapping.Relate(x => x.Prop9, y => y.Prop9);
                mapping.Relate(x => x.Prop10, y => y.Prop10);
            });
        }
    }
}
